public class Solution {
    /**
     *
     * @param root TreeNode类
     * @param o1 int整型
     * @param o2 int整型
     * @return int整型
     */
    public int lowestCommonAncestor (TreeNode root, int o1, int o2) {
        // write code here
        containOr(root, o1, o2);
        return this.res;
    }
    private int res = 0;
    public boolean containOr (TreeNode root, int o1, int o2) {
        if (root == null) return false;
        boolean lson = containOr(root.left, o1, o2);
        boolean rson = containOr(root.right, o1, o2);
        if ((lson && rson) || ((root.val == o1 || root.val == o2) && (lson || rson))) this.res = root.val;
        return root.val == o1 || root.val == o2 || lson || rson;
    }
}

class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}